package com.jintian.hnsj_metting

import android.Manifest
import android.app.AlertDialog
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Color
import android.graphics.SurfaceTexture
import android.media.AudioManager.STREAM_MUSIC
import android.os.Bundle
import android.os.CountDownTimer
import android.os.Handler
import android.speech.tts.TextToSpeech
import android.speech.tts.TextToSpeech.Engine.KEY_PARAM_STREAM
import android.speech.tts.TextToSpeech.Engine.KEY_PARAM_VOLUME
import android.util.Log
import android.view.LayoutInflater
import android.view.TextureView
import android.view.TextureView.SurfaceTextureListener
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextClock
import android.widget.TextView
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import com.arialyy.annotations.DownloadGroup
import com.arialyy.aria.core.Aria
import com.arialyy.aria.core.task.DownloadGroupTask
import com.hikvision.dmb.AlarmButtonCallback
import com.hikvision.dmb.display.InfoDisplayApi
import com.hikvision.dmb.system.InfoSystemApi
import com.hikvision.dmb.util.InfoUtilApi
import com.hikvision.smarteyes.common.SmartConsts
import com.hikvision.smarteyes.facelib.FaceBuildBean
import com.hikvision.smarteyes.smartdev.FaceSdk
import com.hikvision.smarteyes.smartdev.data.BuildModelEvent
import com.hikvision.smarteyes.smartdev.data.FaceRectView
import com.hikvision.smarteyes.smartdev.data.SmartDataEvent
import com.hikvision.smarteyes.utils.log.DFLog
import com.hjq.http.listener.HttpCallbackProxy
import com.jintian.hnsj_metting.api.FaceApi
import com.jintian.hnsj_metting.api.HttpData
import com.jintian.hnsj_metting.api.MeetingApi
import com.jintian.hnsj_metting.api.bean.DeviceIssuePageVO
import com.jintian.hnsj_metting.api.bean.MeetingPageVO
import com.jintian.hnsj_metting.api.bean.RoomPageVO
import com.jintian.hnsj_metting.util.*
import okhttp3.Call
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import java.io.File
import java.util.*


class MainActivity : BaseActivity() {

    companion object {
        const val TAG = "MainActivity"
    }

    private lateinit var tvTime: TextClock
    private lateinit var tvRoomName: TextView

    //    private lateinit var tvRoomStatusBusy: TextView
    private lateinit var tvRoomStatusFree: TextView

    //    private lateinit var layoutCur: View
//    private lateinit var tvCurDate: TextView
//    private lateinit var tvCurTime: TextView
//    private lateinit var tvCurTitle: TextView
//    private lateinit var tvCurAdmin: TextView

    private lateinit var tvLabelList: View
    private lateinit var listMeeting: RecyclerView
    private lateinit var tvEmpty: View

    private lateinit var tvLabelListCur: View
    private lateinit var layoutRecyclerCur: View
    private lateinit var listMeetingCur: RecyclerView


//    private lateinit var faceLayout: View
//    private lateinit var faceView: TextureView
//    private lateinit var tvCertStatus: TextView
//    private lateinit var faceDetachView: FaceRectView

    private lateinit var countDownTimer: CountDownTimer

//    private lateinit var tts: TextToSpeech

//    @Volatile
//    private var faceTimer: Long = 0

//    @Volatile
//    private var fetchTimer: Long = -1

//    private var ttsText: String = ""

//    @Volatile
//    private var downloadTaskId: Long? = null
//    private val issueUserMap = mutableMapOf<String, DeviceIssuePageVO>()
//    private val downloadIssueMap = mutableMapOf<String, DeviceIssuePageVO>()
//    private val issueReportList = mutableListOf<Long>()

//    @Volatile
//    private var issueTimer: Long = 0L

    @Volatile
    private var meetingTimer: Long = -1L
    private val meetingList: MutableList<MeetingPageVO> = mutableListOf()
    private val newList: MutableList<MeetingPageVO> = mutableListOf()

    //    private var curMeeting: MeetingPageVO? = null
    private var curList: MutableList<MeetingPageVO> = mutableListOf()

    @Volatile
    private var meetingStateTimer: Long = 0L

    @Volatile
    private var hasSN = false

//    @Volatile
//    private var openTimer: Long = -1L

//    private lateinit var alarmButtonCallback: AlarmButtonCallback

//    private var roomId: Long? = null;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)

        initView()

//        FaceSdk.get().init(this)
        initTimer()
//        Aria.download(this).register()

//        tts = TextToSpeech(this) {
//            tts.language = Locale.CHINA
//            tts.setSpeechRate(1.5f)
//        }

//        alarmButtonCallback = object : AlarmButtonCallback.Stub() {
//            override fun alarm(btn1: Int, btn2: Int) {
//                if (btn1 == 1) {
//                    openDoor()
//                }
//            }
//        }
//        InfoUtilApi.registerAlarmButtonCallback(alarmButtonCallback)
    }

    override fun onDestroy() {
        super.onDestroy()
//        InfoUtilApi.unregisterAlarmButtonCallback(alarmButtonCallback)
//        Aria.download(this).unRegister()
//        Aria.download(downloadTaskId).stopAllTask();
//        FaceSdk.get().stopFaceTask()
//        FaceSdk.get().destroy()
        countDownTimer.cancel()
//        tts.stop()
//        tts.shutdown()

    }

    override fun onStart() {
        super.onStart()
        request_permissions()
//        if (!EventBus.getDefault().isRegistered(this)) {
//            EventBus.getDefault().register(this)
//        }
//        FaceSdk.get().startFaceDetect()
//        FaceSdk.get().startFaceRecog()
    }

    override fun onStop() {
        super.onStop()
//        FaceSdk.get().stopPreview()
        DFLog.i(TAG, "onStop")
//        if (EventBus.getDefault().isRegistered(this)) {
//            EventBus.getDefault().unregister(this)
//        }
    }

    override fun onResume() {
        super.onResume()
        try {
//            FileUtil.ensureFolder()
            InfoDisplayApi.setNavigationBarEnable(false)
        } catch (e: Exception) {
            e.printStackTrace();
        }
        checkSN()
    }

    private fun checkSN() {
        val sn = DeviceInfo.getSN()
        hasSN = sn != null && sn.isNotEmpty()
        if (hasSN) {
            fetchRoomInfo()
            return
        }

        val builder = AlertDialog.Builder(this)
        builder.setTitle("配置")
        val viewInflated: View =
            LayoutInflater.from(this).inflate(R.layout.dialog_sn_input, null, false)
        val input = viewInflated.findViewById<View>(R.id.input) as EditText
        val input2 = viewInflated.findViewById<View>(R.id.input2) as EditText
        builder.setView(viewInflated)

        builder.setPositiveButton(
            "确定"
        ) { dialog, _ ->
            dialog.dismiss()
            val str = input.text.toString()
            DeviceInfo.setSN(str)

            val str2 = input2.text.toString()
            DeviceInfo.setOtherIds(str2)

            checkSN()
        }
        builder.show()
    }

    private fun initTimer() {
        countDownTimer = object : CountDownTimer(Long.MAX_VALUE, 1000) {
            override fun onTick(p0: Long) {
                if (!hasSN) {
                    return
                }

//                faceTimer++
//                if (faceTimer == 3L) {
//                    Log.d(TAG, "faceTimer==5, stopPreview")
//                    faceLayout.visibility = View.GONE
//                }
//                issueTimer++
//
//                fetchTimer++
//                if (fetchTimer % 5 == 0L) {
//                    reportIssue()
//                }

                meetingTimer++
                if (meetingTimer % 5 == 0L) {
                    fetchMeetingList()
                }

                meetingStateTimer++
                if (meetingTimer % 2 == 0L) {
                    refreshMeetingState()
                }

//                if (openTimer > 0L) {
//                    openTimer--
//                    if (openTimer == 0L) {
//                        closeDoor()
//                    }
//                }
            }

            override fun onFinish() {

            }
        }
        countDownTimer.start()
    }

    private fun initView() {
        tvTime = findViewById(R.id.tv_time)
        tvRoomName = findViewById(R.id.tv_room_name)
//        tvRoomStatusBusy = findViewById(R.id.tv_room_status_busy)
        tvRoomStatusFree = findViewById(R.id.tv_room_status_free)
//        layoutCur = findViewById(R.id.layout_cur)
//        tvCurDate = findViewById(R.id.tv_cur_date)
//        tvCurTime = findViewById(R.id.tv_cur_time)
//        tvCurTitle = findViewById(R.id.tv_cur_title)
//        tvCurAdmin = findViewById(R.id.tv_cur_admin)
        tvLabelList = findViewById(R.id.tv_label_list)
        listMeeting = findViewById(R.id.list_meeting)
        tvEmpty = findViewById(R.id.tv_empty)

        tvLabelListCur = findViewById(R.id.tv_label_list_cur)
        layoutRecyclerCur = findViewById(R.id.layout_recycler_cur)
        listMeetingCur = findViewById(R.id.list_meeting_cur)

//        faceLayout = findViewById(R.id.layout_face)
//        faceView = findViewById(R.id.view_face)
//        tvCertStatus = findViewById(R.id.tv_cert_status)
//        faceDetachView = findViewById(R.id.view_face_detach)
//        faceDetachView.setDrawConfig(Color.BLUE, 2, false, false)

        tvTime.format24Hour = "yyyy-MM-dd HH:mm:ss"
        tvTime.setOnLongClickListener {
            showMenuDialog()
            return@setOnLongClickListener true
        }
//        faceView.keepScreenOn = true
//        faceView.surfaceTextureListener = MyTextureListener()

        listMeeting.adapter = MeetingAdapter(newList)
        listMeetingCur.adapter = MeetingAdapterCur(curList)
    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public fun onEvent(e: SmartDataEvent) {
//        if (e.dataType == SmartConsts.DEV_SMARTDATA_IDENTIFY) {
////            Log.d(TAG, "事件：人脸识别")
//            showFaceInfo()
//        } else if (e.dataType == SmartConsts.DEV_SMARTDATA_LOCATION) {
//            showFaceRect()
////            Log.d(TAG, "事件：人脸信息")
////            faceTimer = 0
////            faceLayout.visibility = View.VISIBLE
//        }
//    }

//    @Subscribe(threadMode = ThreadMode.MAIN)
//    public fun onBuildEvent(event: BuildModelEvent) {
//        Log.d(TAG, "onBuildEvent：${event.progress}")
//        if (event.isDone) {
//            val list = FaceSdk.get().faceBuildResult
//            for (it in list) {
//                val bean = issueUserMap[it.faceUuid] ?: continue
//                issueReportList.add(bean.id)
//            }
//            Log.d(TAG, "onBuildEventSuccess：${list.size}")
//        }
//    }

//    private fun showFaceInfo() {
//        val list = FaceSdk.get().identifyResultDatas
//        if (list == null || list.isEmpty()) {
//            return
//        }
//        val data = list[0]
//        if (data.sim < 0) {
//            ttsText = "认证失败"
//            tvCertStatus.text = "认证失败"
//            tvCertStatus.setTextColor(ContextCompat.getColor(this, R.color.red))
//            tvCertStatus.postDelayed({ tvCertStatus.text = "" }, 1500)
//            speak()
//        } else {
//            ttsText = "认证通过"
//            tvCertStatus.text = "认证通过"
//            tvCertStatus.setTextColor(ContextCompat.getColor(this, R.color.green))
//            tvCertStatus.postDelayed({ tvCertStatus.text = "" }, 1500)
//            speak()
//            openDoor()
//        }
//    }

//    private fun showFaceRect() {
//        val data = FaceSdk.get().faceLocationDatas
//        for (datum in data) {
//            faceDetachView.setFaceRectFs(datum.faceRectFS)
//        }
//    }

//    private fun speak() {
//        if (tts.isSpeaking) {
//            return
//        }
//        tts.speak(
//            ttsText,
//            TextToSpeech.QUEUE_FLUSH,
//            bundleOf(KEY_PARAM_VOLUME to 0.8f, KEY_PARAM_STREAM to STREAM_MUSIC),
//            null
//        )
//    }

//    private fun reportIssue() {
//        if (issueReportList.isEmpty()) {
//            fetchNewIssue()
//        } else {
//            FaceApi.faceBuildReport(
//                this,
//                ids = issueReportList,
//                listener = object : HttpCallbackProxy<HttpData<Any>>(this) {
//                    override fun onHttpEnd(call: Call?) {
//                        super.onHttpEnd(call)
//                        fetchNewIssue()
//                    }
//                })
//        }
//    }

//    private fun fetchNewIssue() {
//        FaceApi.getFaceList(
//            this,
//            listener = object :
//                HttpCallbackProxy<HttpData<List<DeviceIssuePageVO>>>(this) {
//                override fun onHttpSuccess(result: HttpData<List<DeviceIssuePageVO>>?) {
//                    super.onHttpSuccess(result)
//                    val list = result?.data
//                    if (list != null && list.isNotEmpty()) {
//                        issueData(list)
//                    }
//                }
//            })
//    }

//    private fun issueData(beans: List<DeviceIssuePageVO?>) {
//        issueUserMap.clear()
//        downloadIssueMap.clear()
//        issueReportList.clear()
//
//        for (bean in beans) {
//            if (bean == null || bean.userSn == null || bean.userSn.isEmpty() || bean.id == null) {
//                continue
//            }
//            issueUserMap[bean.userSn] = bean
//
//            if (bean.issueType == IssueTypeEnum.USER.code) {
//                if (bean.issueAction == IssueActionEnum.DEL.code) {
//                    FaceSdk.get().deleteFace(bean.userSn)
//                }
//                issueReportList.add(bean.id)
//            } else if (bean.issueType == IssueTypeEnum.FACE.code) {
//                if (bean.issueAction == IssueActionEnum.DEL.code) {
//                    FaceSdk.get().deleteFace(bean.userSn)
//                    issueReportList.add(bean.id)
//                } else if (bean.issueAction == IssueActionEnum.ADD.code) {
//                    downloadIssueMap[bean.facePic] = bean
//                }
//            } else if (bean.issueType == IssueTypeEnum.DOOR_PWD.code) {
//                issueReportList.add(bean.id)
//            }
//        }
//        if (downloadIssueMap.isNotEmpty()) {
//            downloadPics()
//        }
//    }

//    private fun downloadPics() {
//        val list = downloadIssueMap.values.map {
//            it.facePic
//        }
//        if (downloadTaskId != null) {
//            Aria.download(downloadTaskId).stopAllTask()
//        }
//        downloadTaskId = Aria.download(this)
//            .loadGroup(list)
//            .setDirPath(FileUtil.getTempFolder())
//            .ignoreTaskOccupy()
//            .unknownSize()
//            .create()
//    }

//    @DownloadGroup.onTaskComplete
//    public fun downloadComplete(task: DownloadGroupTask) {
//        Log.d(TAG, "downloadComplete")
//        val list = task.entity.subEntities
//        if (list.isEmpty()) {
//            return
//        }
//        val dir = File(task.entity.dirPath)
//        val files = dir.listFiles()
//        if (files == null || files.isEmpty()) {
//            return
//        }
//
//        val newList = mutableListOf<File>()
//        for (entity in list) {
//            val file = File(entity.filePath)
//            if (!file.exists()) {
//                continue
//            }
//            val userSn = downloadIssueMap[entity.realUrl]?.userSn ?: continue
//            if (userSn.isEmpty()) {
//                continue
//            }
//            val newFile = File(FileUtil.getFolder(), userSn)
//            if (newFile.exists()) {
//                newFile.delete()
//                FaceSdk.get().deleteFace(userSn)
//            }
//            val b = file.renameTo(newFile)
//            if (b) {
//                newList.add(newFile)
//            }
//            Log.d(TAG, "建模newList：$newList")
//
//        }
//        dir.delete()
//
//        if (newList.isEmpty()) {
//            return
//        }
//
//        val beans = newList.map {
//            FaceBuildBean().apply {
//                faceUuid = it.name
//                picPath = it.path
//            }
//        }
//        val code = FaceSdk.get().faceBuild(beans)
//        Log.d(TAG, "建模code：$code")
//    }

    private fun fetchMeetingList() {
        MeetingApi.getMeetingList(
            this,
            listener = object : HttpCallbackProxy<HttpData<List<MeetingPageVO>>>(this) {
                override fun onHttpSuccess(result: HttpData<List<MeetingPageVO>>?) {
                    super.onHttpSuccess(result)
                    val newList = result?.data ?: listOf()
                    meetingList.clear()
                    meetingList.addAll(newList)
                    refreshMeetingState()
                }
            })
    }

    fun refreshMeetingState() {
        newList.clear()
        curList.clear()

        if (meetingList.isNotEmpty()) {
            val now = Calendar.getInstance()
            now.set(Calendar.SECOND, 0)
            now.set(Calendar.MILLISECOND, 0)

            meetingList.forEach {
                if (it.beginTime != null && it.endTime != null) {
                    if ((it.beginTime.before(now.time) || it.beginTime.equals(now.time))
                        && (it.endTime.after(now.time) || it.endTime.equals(now.time))
                    ) {
                        val curMeeting = MeetingPageVO()
                        curMeeting.id = it.id
                        curMeeting.title = it.title
                        curMeeting.beginTime = it.beginTime
                        curMeeting.endTime = it.endTime
                        curMeeting.creatorName = it.creatorName
                        curMeeting.creatorId = it.creatorId
                        curMeeting.desc = it.desc
                        curMeeting.mine = it.mine
                        curMeeting.roomId = it.roomId
                        curMeeting.roomName = it.roomName

                        curList.add(curMeeting)
                    } else {
                        newList.add(it)
                    }
                } else {
                    newList.add(it)
                }
            }
        }
        listMeeting.adapter?.notifyDataSetChanged()
        listMeetingCur.adapter?.notifyDataSetChanged()

        if (curList.isNotEmpty()) {
            tvRoomStatusFree.visibility = View.INVISIBLE
        }else{
            tvRoomStatusFree.visibility = View.VISIBLE
        }

//        if (curMeeting == null) {
////            layoutCur.visibility = View.INVISIBLE
//            tvRoomStatusFree.visibility = View.VISIBLE
////            tvRoomStatusBusy.visibility = View.GONE
////            layoutCur.visibility = View.GONE
//        } else {
//            tvRoomStatusFree.visibility = View.GONE
////            tvRoomStatusBusy.visibility = View.VISIBLE
////            layoutCur.visibility = View.VISIBLE
////            tvCurTime.text =
////                TimeUtil.formatHM(curMeeting?.beginTime) + " - " + TimeUtil.formatHM(
////                    curMeeting?.endTime
////                )
////            tvCurDate.text =
////                TimeUtil.formatMD(curMeeting?.beginTime)
////            tvCurTitle.text = curMeeting?.title
////            tvCurAdmin.text = curMeeting?.creatorName
//        }

        if (newList.isEmpty()) {
            tvLabelList.visibility = View.INVISIBLE
        } else {
            tvLabelList.visibility = View.VISIBLE
        }
    }

    private fun fetchRoomInfo() {
        MeetingApi.getMeetingRoom(
            this,
            listener = object : HttpCallbackProxy<HttpData<RoomPageVO>>(this) {
                override fun onHttpSuccess(result: HttpData<RoomPageVO>?) {
                    super.onHttpSuccess(result)
                    val name = result?.data?.name
                    runOnUiThread {
                        tvRoomName.text = name
//                        roomId = result?.data?.id
                    }
                }
            })
    }

    /****************************************/

    // 请求多个权限
    private fun request_permissions() {
        // 创建一个权限列表，把需要使用而没用授权的的权限存放在这里
        val permissionList: MutableList<String> = ArrayList()

        // 判断权限是否已经授予，没有就把该权限添加到列表中
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED
        ) {
            permissionList.add(Manifest.permission.CAMERA)
        }
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED
        ) {
            permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE)
        }
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED
        ) {
            permissionList.add(Manifest.permission.READ_EXTERNAL_STORAGE)
        }

        // 如果列表为空，就是全部权限都获取了，不用再次获取了。不为空就去申请权限
        if (permissionList.isNotEmpty()) {
            ActivityCompat.requestPermissions(
                this,
                permissionList.toTypedArray(), 1002
            )
        } else {
            Log.i(TAG, "request_permissions: no need request.")
        }
    }

    override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<out String>,
        grantResults: IntArray
    ) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        Log.d(TAG, "onRequestPermissionsResult, $requestCode,${grantResults[0]}")
        when (requestCode) {
            1002 ->                 // 1002请求码对应的是申请多个权限
                if (grantResults.isNotEmpty()) {
                    // 因为是多个权限，所以需要一个循环获取每个权限的获取情况
                    var i = 0
                    while (i < grantResults.size) {
                        // PERMISSION_DENIED 这个值代表是没有授权，我们可以把被拒绝授权的权限显示出来
                        if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
                            Log.i(
                                TAG,
                                "onRequestPermissionsResult: reject permission.exit"
                            )
                            finish()
                        }
                        i++
                    }
                }
        }
    }

//    private fun openDoor() {
//        openTimer = 5L
//        InfoUtilApi.setElectricLock(1, false)
//    }

//    private fun closeDoor() {
//        InfoUtilApi.setElectricLock(1, true)
//    }

    private fun showMenuDialog() {
        val menus = mutableListOf("重启电脑", "重启应用")
//        if (BuildConfig.DEBUG) {
        menus.add("打开调试")
        menus.add("退出应用")
//        }
        android.app.AlertDialog.Builder(this)
            .setItems(menus.toTypedArray()) { p0, p1 ->
                when (p1) {
                    0 -> InfoSystemApi.reboot()
                    1 -> {
                        Handler().postDelayed({
                            val launchIntent =
                                packageManager.getLaunchIntentForPackage(application.packageName)
                            launchIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
                            startActivity(launchIntent)
                        }, 200) // 1秒钟后重启应用
                    }

                    2 -> InfoSystemApi.openAdb()
                    3 -> InfoUtilApi.closeDown(application.packageName)
                }
            }
            .create()
            .show()
    }

//    inner class MyTextureListener : SurfaceTextureListener {
//        override fun onSurfaceTextureAvailable(p0: SurfaceTexture, p1: Int, p2: Int) {
////            Log.i(TAG, "onSurfaceTextureAvailable 33333333")
//            FaceSdk.get().startPreview(faceView)
//        }
//
//        override fun onSurfaceTextureSizeChanged(p0: SurfaceTexture, p1: Int, p2: Int) {
////            Log.i(TAG, "onSurfaceTextureSizeChanged 33333333")
//        }
//
//        override fun onSurfaceTextureDestroyed(p0: SurfaceTexture): Boolean {
////            Log.i(TAG, "onSurfaceTextureDestroyed 33333333")
//            return true
//        }
//
//        override fun onSurfaceTextureUpdated(p0: SurfaceTexture) {
////            Log.i(TAG, "onSurfaceTextureUpdated 33333333")
//        }
//
//    }

    inner class MeetingAdapter(private val list: List<MeetingPageVO>) :
        RecyclerView.Adapter<MyVH>() {

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyVH {
            val itemView =
                LayoutInflater.from(parent.context).inflate(R.layout.item_meeting, parent, false)
            return MyVH(itemView)
        }

        override fun getItemCount(): Int {
            return list.size
        }

        override fun onBindViewHolder(holder: MyVH, position: Int) {
            holder.bindData(list[position])
        }
    }

    inner class MeetingAdapterCur(private val list: List<MeetingPageVO>) :
        RecyclerView.Adapter<MyVH>() {

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyVH {
            val itemView =
                LayoutInflater.from(parent.context).inflate(R.layout.item_meeting_cur, parent, false)
            return MyVH(itemView)
        }

        override fun getItemCount(): Int {
            return list.size
        }

        override fun onBindViewHolder(holder: MyVH, position: Int) {
            holder.bindData(list[position])
        }
    }

    inner class MyVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private var tvDate: TextView;
        private var tvTime: TextView;
        private var tvTitle: TextView;
        private var tvAdmin: TextView;
        private var tvRoom: TextView;

        init {
            tvDate = itemView.findViewById(R.id.tv_date)
            tvTime = itemView.findViewById(R.id.tv_time)
            tvTitle = itemView.findViewById(R.id.tv_title)
            tvAdmin = itemView.findViewById(R.id.tv_admin)
            tvRoom = itemView.findViewById(R.id.tv_room_name)
        }

        fun bindData(item: MeetingPageVO?) {
            tvDate.text =
                TimeUtil.formatMD(item?.beginTime)
            tvTime.text =
                TimeUtil.formatHM(item?.beginTime) + " - " + TimeUtil.formatHM(item?.endTime)
            tvTitle.text = item?.title
            tvAdmin.text = item?.creatorName
            tvRoom.text = item?.roomName
        }
    }
}